package com.lin.missyou.api.v1;

import com.lin.missyou.exception.http.NotFoundException;
import com.lin.missyou.model.Activity;
import com.lin.missyou.service.ActivityService;
import com.lin.missyou.vo.ActivityCouponVo;
import com.lin.missyou.vo.ActivityPureVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 *
 * 当前的spu所属的分类的coupon信息
 * @author gcq
 * @Create 2021-11-03
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    ActivityService activityService;

    @GetMapping("/name/{name}")
    public ActivityPureVo getHomeActivity(@PathVariable String name)
    {
        Activity activity = activityService.getByName(name);
        if(activity == null)
        {
            throw new NotFoundException(40001);
        }
        ActivityPureVo vo = new ActivityPureVo(activity);
        return vo;
    }

    @GetMapping("/name/{name}/with_coupon")
    public ActivityCouponVo getActivityWithCoupons(@PathVariable String name)
    {
        Activity activity = activityService.getByName(name);
        if(activity == null)
        {
            throw new NotFoundException(40001);
        }
        ActivityCouponVo vo = new ActivityCouponVo(activity);
        return vo;
    }
}